package model

import (
	"fmt"
	"log"
	"microprj/groupWeatherArea/global"
	"time"
)

type Weather struct {
	Province string `json:"province"`
	City     string `json:"city"`
	Country  string `json:"country"`
	DayTime  string `json:"day_time"`
	Highest  int    `json:"highest"`
	Minimum  int    `json:"minimum"`
	AvgTemp  int    `json:"avg_temp"`
	HTemp    int    `json:"h_temp"`
}

func GetWeatherByCountry(w *Weather) {

	var list []Weather

	global.DB.Raw("select province,city,country,day_time,highest,minimum,avg_temp,h_temp from histry_weather where country='天津' ").Scan(&list)

	//fmt.Println(list)

	fmt.Println(len(list))
	GetHTemp(&list[0])
	//for _,v:=range list{
	//
	//}
}

func GetHTemp(w *Weather)  {
	t3,e:=time.ParseInLocation("2006年01月02日",w.DayTime,time.Local)


	t1:=t3.Add(-time.Hour*48)
	t2:=t3.Add(-time.Hour*24)
	t4:=t3.Add(time.Hour*24)
	t5:=t3.Add(time.Hour*48)
	if e!=nil{
		log.Fatal(e.Error())
	}
	fmt.Println(t1)
	fmt.Println(t2)
	fmt.Println(t3)
	fmt.Println(t4)
	fmt.Println(t5)

}
func GetWeatherWithDayAndCountry(w *Weather,day string)  {
	var list []Weather

	global.DB.Raw("select province,city,country,day_time,highest,minimum,avg_temp,h_temp from histry_weather where country=? and day_time=? ",w.Country,day).Scan(&list)


}

